package adminAction;

import dao.OrderDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/admin/adminAction/StaChangeServlet")
public class StaChangeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sta = req.getParameter("optionsRadios");
        String orderId = req.getParameter("orderId");
        OrderDao orderDao = new OrderDao();
        if (sta.equals("已发货")){
            orderDao.updateDeliverById(orderId);
        }
        Integer row = orderDao.updateStaById(orderId,sta);
        if (row>0){
            req.getRequestDispatcher("../page/order-list.jsp?flag=1").forward(req,resp);
        }else
        req.getRequestDispatcher("../adminAction/OrderDetailServlet?orderId="+orderId+"&chose=2").forward(req,resp);
    }
}
